package com.yuhang.controller;


import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yuhang.entity.HyActivity;
import com.yuhang.entity.HyBill;
import com.yuhang.entity.HyUser;
import com.yuhang.service.HyActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuhang
 * @since 2021-04-25
 */
@RestController
@RequestMapping("/hy-activity")
public class HyActivityController {

    @Autowired
    private HyActivityService hyActivityService;

    @RequestMapping("/showAllActivity")
    public Map<String,Object> showAllActivity(@RequestParam(value = "page",defaultValue = "1")int pageNum,
                                              @RequestParam(value = "limit",defaultValue = "5")int pageSize,
                                              @RequestParam(value = "liketitle",defaultValue = "")String liketitle){
        IPage<HyActivity> page = hyActivityService.selectByPage(pageNum, pageSize,liketitle);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        map.put("count",page.getTotal());
        map.put("data",page.getRecords());
        map.put("msg","");
        return map;
    }

    @RequestMapping("/addActivity")
    public Map<String,Object> addActivity(HyActivity hyActivity){
        hyActivityService.save(hyActivity);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        return map;
    }

    @RequestMapping("/updateActivity")
    public Map<String,Object> updateActivity(HyActivity hyActivity){
        hyActivityService.updateById(hyActivity);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        return map;
    }

    @RequestMapping("/deleteActivity")
    public Map<String,Object> deleteActivity(Integer id){
        hyActivityService.removeById(id);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        return map;
    }
    @RequestMapping("/getNowTime")
    public Map<String,Object> getNowTime(){
        DateTime nowtime = DateUtil.date();
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        map.put("nowtime",nowtime);
        return map;
    }
}
